<!-- 2. jQuery导入，建议使用1.9以上的版本 -->
var xmlHttpRequest;
function createXMLHttpRequest()
{
    if (window.XMLHttpRequest) //非IE浏览器
    {
        xmlHttpRequest = new XMLHttpRequest();
    }
    else if (window.ActiveObject)//IE6以上版本的IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Msxml2.XMLHTTP");
    }
    else //IE6及以下版本IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Microsoft.XMLHTTP");
    }
}
var quantity;
var whatitem;
var obj;
function updateCart(event) {
    //var username = document.NewAccountForm.username.value;
    //var workingItemId = document.getElementById('workingItemId').value;
    //sendRequest("updateCartQuantities?username=" + username);
    obj = event.srcElement;
    quantity = event.srcElement.value;
    whatitem = event.srcElement.name;
    // var quantity = document.getElementById("quantity").value;
    // var whatitem = document.getElementById("quantity").getAttribute("name");
    sendRequest("updateCartJSServlet?quantity="+ quantity+"&whatitem="+whatitem);
    //sendRequest("updateCartQuantities");
}

function sendRequest(url) {
    createXMLHttpRequest();
    xmlHttpRequest.open("GET", url, true);
    xmlHttpRequest.onreadystatechange = processResponse;
    xmlHttpRequest.send(null);
}

function processResponse(event) {
    if (xmlHttpRequest.readyState == 4) {
        if (xmlHttpRequest.status == 200) {
            var resp = xmlHttpRequest.responseText;
            var array = resp.split(",");
            var quantity = obj;
            var total = obj.parentElement.nextElementSibling.nextElementSibling.firstChild;
            var subtotal = document.getElementById("subtotal");

            // if(array[0]<=0){
            //     quantity.parentElement.parentElement.remove();
            //     total.innerText = 0;
            //     subtotal.innerText=array[2];
            //
            // }else{
                quantity.innerText = array[0];
                total.innerText = "$"+array[1];
                subtotal.innerText = "$"+array[2];
            // }




        }
    }
}
